package com.gaia.member.gaiatt.mygaia;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.gaia.member.gaiatt.R;
import com.gaia.member.gaiatt.bean.FavorableTickeBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by zhangHaiTao on 2016/5/6.
 * 优惠券
 */
public class CouponActivity extends AppCompatActivity {

    @Bind(R.id.tv_title_title_bar)
    TextView tvTitleToolBar;
    @Bind(R.id.lv_tickets)
    ListView lvTickets;
    List<FavorableTickeBean> tickets = new ArrayList<>();
    private Activity mContext;
    private FavorableTicketAdapter favorableTicketAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;
        setContentView(R.layout.activity_coupon);
        ButterKnife.bind(this);

        for (int i = 0; i < 5; i++) {
            FavorableTickeBean bean = new FavorableTickeBean();
            tickets.add(bean);
        }

        tvTitleToolBar.setText("优惠券");

        favorableTicketAdapter = new FavorableTicketAdapter(mContext, tickets);
        lvTickets.setAdapter(favorableTicketAdapter);

    }


    class FavorableTicketAdapter extends BaseAdapter {
        Context context;
        List<FavorableTickeBean> datas;

        FavorableTicketAdapter(Context context, List<FavorableTickeBean> datas) {
            this.context = context;
            this.datas = datas;
        }

        @Override
        public int getCount() {
            return datas.size();
        }

        @Override
        public Object getItem(int position) {
            return datas.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder viewHolder;
            if (convertView == null) {
                convertView = View.inflate(context, R.layout.item_list_mygaia_coupon, null);
                viewHolder = new ViewHolder(convertView);
                convertView.setTag(viewHolder);
            } else {
                viewHolder = (ViewHolder) convertView.getTag();
            }
            //动态修改内容
            viewHolder.tvDeadlineTime.setText("亲，优惠哦");
            return convertView;
        }

        class ViewHolder {
            @Bind(R.id.tv_ticket_name)
            TextView tvTicketName;
            @Bind(R.id.tv_discount)
            TextView tvDiscount;
            @Bind(R.id.tv_deadline_time)
            TextView tvDeadlineTime;
            @Bind(R.id.tv_desc)
            TextView tvDesc;

            ViewHolder(View view) {
                ButterKnife.bind(this, view);
            }
        }
    }
}
